﻿using BPMS.Business;
using BPMS.Entity;
using BPMS.IBusiness;
using DotNet.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BPMS.MVC.Controllers
{
    public class ButtonController : BaseController
    {
        BPMS_ButtonIBLL bpms_buttonibll = new BPMS_ButtonBLL();
        BPMS_Button bpms_button = new BPMS_Button();

        #region 操作按钮列表
        /// <summary>
        /// 操作按钮列表
        /// </summary>
        /// <returns></returns>
        public ActionResult ButtonList()
        {
            return View();
        }
        /// <summary>
        /// 初始化处理数据
        /// </summary>
        public void LoadAction()
        {
            string active = Request["action"];                                          //提交类型
            string pqGrid_Sort = Request["pqGrid_Sort"];                                //要显示字段
            string key = Request["key"];                                                //主键
            string Parm_Key_Value = Request["Parm_Key_Value"];                          //搜索条件键值
            switch (active)
            {
                case "GridBindList"://加载列表
                    Hashtable parm = HashtableHelper.String_Key_ValueToHashtable(Parm_Key_Value);
                    Response.Write(JsonHelper.PqGridJson<BPMS_Button>(bpms_buttonibll.GetListWhere(parm), pqGrid_Sort));
                    Response.End();
                    break;
                case "Delete":    //删除数据
                    Response.Write(bpms_buttonibll.Delete(key));
                    Response.End();
                    break;
                default:
                    break;
            }
        }
        #endregion

        #region 操作按钮表单
        /// <summary>
        /// 操作按钮表单
        /// </summary>
        /// <returns></returns>
        public ActionResult ButtonForm()
        {
            return View();
        }
        /// <summary>
        /// 确认事件
        /// </summary>
        /// <param name="bpms_button">操作按钮信息</param>
        /// <returns></returns>
        public ActionResult AcceptClick(BPMS_Button bpms_button)
        {
            string key = Request["key"];                                                //主键
            bool IsOk = false;
            if (!string.IsNullOrEmpty(key))//判断是否编辑
            {
                bpms_button.ButtonId = key;
                bpms_button.ModifyDate = DateTime.Now;
                bpms_button.ModifyUserId = SessionHelper.GetSessionUser().UserId;
                bpms_button.ModifyUserName = SessionHelper.GetSessionUser().UserName;
                IsOk = bpms_buttonibll.Update(bpms_button);
            }
            else
            {
                bpms_button.ButtonId = CommonHelper.GetGuid;
                bpms_button.CreateUserId = SessionHelper.GetSessionUser().UserId;
                bpms_button.CreateUserName = SessionHelper.GetSessionUser().UserName;
                IsOk = bpms_buttonibll.Insert(bpms_button);
            }
            return Content(IsOk.ToString().ToLower());
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        /// <param name="key">主键</param>
        /// <returns></returns>
        public ActionResult InitControl(string key)
        {
            if (!string.IsNullOrEmpty(key))
            {
                bpms_button = bpms_buttonibll.GetEntity(key);
                return Content(JsonHelper.ObjectToJson(bpms_button));
            }
            return null;
        }
        #endregion
    }
}
